﻿package org.openChart.sprite.elements 
{
	import org.openChart.display.DisplayElement;
	import org.openChart.meta.BarChart;
	import org.openChart.meta.ChartType;
	import org.openChart.sprite.CommandHandler;
	
	/**
	 * ...
	 * @author Chongyuan
	 */
	public class ElementFactory 
	{
		
		public function ElementFactory() 
		{
			
		}
		
		public static function create(displayElement:DisplayElement, commandHandler:CommandHandler):ElementSprite
		{
			//trace("creating the element sprite ");
			var chartType:String = displayElement.parent.parent.parent.chartType;
			var elementSprite:ElementSprite;
			switch( chartType)
			{
				case ChartType.CUMULATE_BAR_CHART_2D:
				case ChartType.DRUSY_BAR_CHART_2D:
				case ChartType.PERCENT_BAR_CHART_2D:
					elementSprite = new Bar2d(displayElement, commandHandler);
					break;
				case ChartType.CUMULATE_BAR_CHART_3D_CONE:
				case ChartType.DRUSY_BAR_CHART_3D_CONE:
				case ChartType.PERCENT_BAR_CHART_3D_CONE:
					elementSprite = new Bar3dCone(displayElement, commandHandler);
					break;
				case ChartType.CUMULATE_BAR_CHART_3D_CUBE:
				case ChartType.DRUSY_BAR_CHART_3D_CUBE:
				case ChartType.PERCENT_BAR_CHART_3D_CUBE:
					elementSprite = new Bar3dCube(displayElement, commandHandler);
					break;
				case ChartType.DRUSY_BAR_CHART_3D_CYLINDER:
				case ChartType.CUMULATE_BAR_CHART_3D_CYLINDER:
				case ChartType.PERCENT_BAR_CHART_3D_CYLINDER:
					elementSprite = new Bar3dCylinder(displayElement, commandHandler);
					break;
				case ChartType.CUMULATE_BAR_CHART_3D_PYRAMID:
				case ChartType.DRUSY_BAR_CHART_3D_PYRAMID:
				case ChartType.PERCENT_BAR_CHART_3D_PYRAMID:
					elementSprite = new Bar3dPyramid(displayElement, commandHandler);
					break;
				case ChartType.CUMULATE_LINE_CHART:
				case ChartType.DRUSY_LINE_CHART:
				case ChartType.PERCENT_LINE_CHART:
					elementSprite = new LineElement(displayElement, commandHandler);
					break;
				case ChartType.PIE_CHART_2D:
				case ChartType.DISCONNECTED_PIE_CHART_2D:
					elementSprite = new Pie2d(displayElement, commandHandler);
					break;
				case ChartType.PIE_CHART_3D:
				case ChartType.DISCONNECTED_PIE_CHART_3D:
					elementSprite = new Pie3d(displayElement, commandHandler);
					break;
				default:
					throw new Error("Open Chart does not support this type of chart.");
			}
			return elementSprite;
		}
	}
	
}